package com.nj.interfaces.login.dao;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;

import com.nj.framework.dao.StandardGenericDAO;

/**
 * 项目名称：  AttendenceSys_Server   
 * 类名称：  UserLoginDAO   
 * 描述：  
 * @author  吴志虎   
 * 创建时间：  2016年1月13日 下午7:29:43 
 *
 */
@Repository
public class UserDAO extends StandardGenericDAO{
	/** 
	 * 方法名：  queryUser 
	 * 描述：  
	 * @author  吴志虎   
	 * @param userCode
	 * @param passWord
	 * @return
	 * @throws DataAccessException
	 * @throws ClassNotFoundException
	 *
	 */
	public int queryUser(String userCode,String passWord) throws DataAccessException, ClassNotFoundException{
		String sql="SELECT COUNT(1) FROM fnd_user fu WHERE fu.user_code=? AND fu.user_pwd=?";
		return findByObject(sql, Integer.class, userCode,passWord);
	}
	
	/** 
	 * 方法名：  queryUserInfo 
	 * 描述：  获取用户信息
	 * @author  吴志虎   
	 * @param userCode
	 * @return
	 *
	 */
	public Map queryUserInfo (String userCode) {
		Map map = new HashMap();
		StringBuilder sql = new StringBuilder();
		sql.append( "SELECT F.PK_USER_ID userId,");
		sql.append( "F.USER_CODE userCode,");
		sql.append( " F.USER_NAME userName,");
		sql.append( "F.SOURCE_TYPE_ID sourceTypeId,");
		sql.append( "DECODE(F.SOURCE_TYPE_ID, 1, '老师', 2, '学生') sourceTypeName,");
		sql.append( "F.USER_SEX userSex,");
		sql.append( " F.USER_EMAIL userEmail,");
		sql.append( " F.USER_DESC userDesc,");
		sql.append( "F.USER_CARDCODE userCardCode,");
		sql.append( "F.ENTRANCE_TIME entranceTime,");
		sql.append( "F.USER_BIRTH userBirth,");
		sql.append( " (SELECT ROUND(MONTHS_BETWEEN(SYSDATE,");
		sql.append( "                             TO_DATE('2000-11-11', 'YYYY-mm-DD')) / 12) AGE");
		sql.append( "  FROM DUAL) AGE,");
		sql.append( "FC.COLLEGE_NAME collegeName,");
		sql.append( " C.CLASS_NAME className");
		sql.append( "FROM FND_USER F, FND_COLLEGE FC, FND_CLASS C");
		sql.append( "WHERE F.FK_COLLEGE_ID = FC.PK_COLLEGE_ID");
		sql.append( " AND C.PK_CLASS_ID = F.FK_CLASS_ID");
		sql.append( " AND F.USER_CODE = ?");
		try {
			map = (Map) findByObject(sql.toString(),Object.class,userCode);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return map;
		
	}
	
	
	

	/** 
	 * 方法名：  getUserCondition 
	 * 描述：  获取用户奖惩列表
	 * @author  吴志虎   
	 * @param userCode
	 * @return
	 *
	 */
	public List<Map<String, Object>> getUserCondition (String userCode) {
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>> ();
		StringBuilder sql = new StringBuilder();
		sql.append( " SELECT FUC.CONDITION_DESC,FUC.CONDITION_DATE FROM fnd_user_condition ");
		sql.append(  " FUC WHERE FUC.USER_CODE =? ORDER BY FUC.CONDITION_DATE DESC ");
		list = findAllList(sql.toString(),userCode);
		return list;
	}
	
	
	
}
